//
//  ByRecordListForemanCell.m
//  recordworktool_ios
//
//  Created by mc on 2017/12/19.
//  Copyright © 2017年 ZhangZhanbin. All rights reserved.
//

#import "ByRecordListForemanCell.h"
#import "ByRecordListForemanView.h"

@implementation ByRecordListForemanCell

+ (instancetype)cellWithTableView:(UITableView*)tableView {
    
    static NSString *cellIdentifier = @"ByRecordListForemanCell";
    ByRecordListForemanCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
    
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self =  [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        //[self createViews];
    }
    return self;
}


- (void)createViews{
    
    for (UIView *view in self.contentView.subviews) {
        [view removeFromSuperview];
    }
    
    self.contentView.backgroundColor = BY_BACKGROUND_COLOR;
    
    UIView *view = [[UIView alloc] init];
    [self.contentView addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(10);
        make.right.equalTo(self.contentView).offset(-10);
        make.top.equalTo(self.contentView).offset(0);
        make.bottom.equalTo(self.contentView).offset(0);
    }];
    view.backgroundColor = [UIColor whiteColor];
    view.layer.cornerRadius = 10;
    
    for (int i = 0; i < _dataArray.count; i++){
        
        ByNetModel *netModel = [_dataArray objectAtIndex:i];
        ByRecordListForemanView *recordView = [[ByRecordListForemanView alloc] initWithFrame:CGRectMake(0, i * 60, SCREEN_WIDTH - 20, 60)];
        recordView.netModel = netModel;
        [view addSubview:recordView];
        recordView.detailBtn.tag = 100 + i;
        [recordView.detailBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        
        if (i != 2) {
            UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(0, i * 60 + 59 , SCREEN_WIDTH - 20, 1)];
            line.backgroundColor = BY_LINE_COLOR;
            [view addSubview:line];
        }
    }
    
}

- (void)setDataArray:(NSMutableArray *)dataArray{
    _dataArray = dataArray;
    [self createViews];
}

- (void)btnAction:(UIButton *)btn{
    self.indexAtView(btn.tag - 100);
}
@end
